package cn.wolfcode.business.controller;

import cn.wolfcode.business.domain.vo.StatementItemVO;
import cn.wolfcode.business.service.IBusStatementItemService;
import cn.wolfcode.common.annotation.Log;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import cn.wolfcode.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 结算单明细Controller
 * 
 * @author wolfcode
 * @date 2025-05-11
 */
@RestController
@RequestMapping("/business/item")
public class BusStatementItemController extends BaseController
{
    @Autowired
    private IBusStatementItemService busStatementItemService;

    /**
     * 新增结算单明细
     */
    @PreAuthorize("@ss.hasPermi('business:item:add')")
    @Log(title = "结算单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StatementItemVO vo)
    {
        return toAjax(busStatementItemService.itemSave(vo));
    }

    /**
     * 根据结算单 id 查询结算单明细列表
     */
    @GetMapping(path = "/{id}")
    public AjaxResult getStatementItemListByStatementId(@PathVariable Long id)
    {
        return AjaxResult.success(busStatementItemService.getStatementItemListByStatementId(id));
    }

    /**
     * 支付功能
     */
    @PatchMapping("/{statementId}")
    public AjaxResult pay(@PathVariable Long statementId){
        return toAjax(busStatementItemService.pay(statementId));
    }
}
